<template>
<view class="page__bd">
	<view class="daui-custom">
		<view class="daui-navbar fixed" :class="scrollTop < 100?'show':'hide'" :style="[{height:CustomBar + 'px',paddingTop:StatusBar + 'px',backgroundColor:'rgba(244,63,59,' + (scrollTop>CustomBar?1:scrollTop/CustomBar) + ')'}]">
			<view class="daui-navbar__hd text-bold">
				<view class="text-white text-xl">
					个人中心
				</view>
			</view>
			<view class="daui-navbar__hd text-white">
				<navigator url="/pagesA/setting/setting" hover-class="none" class="iconfontzz icon-settings"> 设置</navigator>
				<!-- #ifndef H5 -->
				<view hover-class="none" class="iconfontzz icon-saomiao padding-lr-sm" @tap="doScan" style="display: none;"></view>
				<!-- #endif -->
				<navigator url="/pagesA/message/messageList" hover-class="none" class="iconfontzz icon-noticefill padding-lr-sm" style="display: none;"></navigator>
				<navigator url="/pages/chat/chatList" hover-class="none" class="iconfontzz icon-liaotian padding-lr-sm" style="display: none;"></navigator>
			</view>
		</view>
	</view>
	<view class="bghead-wrap bg-gradual-primary" :style="[{paddingTop:(CustomBar + 30) + 'px'}]"></view>
	<view class="myhead-wrap">
		<view class="myinfo-box" v-if="isLogin">
			<view class="myinfo-avatar">
				<view class="daui-avatar round lg"><image :src="moonInfo.avatar" class="round"></image></view>
			</view>
			<view class="daui-cell">
				<view class="daui-cell__bd">
					<view class="myinfo-title">
						<text class="myinfo-username">
							{{moonInfo.username}}
						</text>
						<image :src="moonInfo.levelicon" mode="heightFix" class="myinfo-levelicon" v-if="moonInfo.levelicon"></image>
					</view>
					<view class="text-black text-sm flex" style="display: none;">
						<view class="text-cut">
							ID：{{moonInfo.uid}}
							<text class="icon-copy text-white margin-left-xs"></text>
						</view>
					</view>
					<view class="text-grayDark text-sm flex">
						{{configInfo.balance_name}}：{{moonInfo.realbalance}}
						<text class="margin-left-sm" style="display:none">
						组别：{{moonInfo.realgroup}}
						</text>
						<text class="margin-left-sm" v-if="moonInfo.is_creditacc">
							信用金额：{{moonInfo.realcredit}}
						</text>
					</view>
					<view class="text-grayDark text-sm" v-if="moonInfo.store_name">
						门店名称：{{moonInfo.store_name}}
					</view>
				</view>
				<view class="daui-cell__ft">
					<!-- #ifdef H5 -->
						<view>
							<button class="daui-btn daui-btn_sm line-orange round" open-type="getUserInfo" v-if="!moonInfo.unionid" @click="weixinBindH5">
								绑定微信号
							</button>
						</view>
						<!--
						<button class="daui-btn daui-btn_sm line-grayDark round" @click="openProfile">编辑</button>
						-->
					<!-- #endif -->
					<!-- #ifdef MP-WEIXIN -->
						<view>
							<button class="daui-btn daui-btn_sm line-orange round" open-type="getUserInfo" v-if="!moonInfo.unionid" @click="weixinBindMp">
								绑定微信号
							</button>
						</view>
						<!--
						<button class="daui-btn daui-btn_sm line-orange round" open-type="getUserInfo" @tap="wxGetUserInfo" v-if="moonInfo.needUserinfo == 1">
							授权用户信息
						</button>
						<button class="daui-btn daui-btn_sm line-grayDark round" @click="openProfile" v-else>编辑</button>
						-->
					<!-- #endif -->
					<!-- #ifdef APP-PLUS -->
						<view>
							<button class="daui-btn daui-btn_sm line-orange round" open-type="getUserInfo" v-if="!moonInfo.unionid" @click="weixinBindAppPlus">
								绑定微信号
							</button>
						</view>
						<!--
						<button class="daui-btn daui-btn_sm line-grayDark round" @click="openProfile">编辑</button>
						-->
					<!-- #endif -->
				</view>
			</view>
		</view>
		<view class="myinfo-box menu-avatar" v-else>
			<view class="daui-cell" @tap="openLogin">
				<view class="daui-cell__hd">
					<image :src="danceData.webURL+'/static/danceui/images/avatar/none.png'" mode="widthFix" class="daui-avatar"></image>
				</view>
				<view class="daui-cell__bd">
					<view class="text-black">注册 / 登录</view>
				</view>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<view class="cu-list menu-avatar" style="display: none;">
				<view class="cu-item">
					<view class="daui-avatar round lg bg-white shadow"><text class="iconfontzz icon-peoplefill text-red"></text></view>
					<view class="content">
						<button class="daui-btn bg-green round lg shadow" open-type="getUserInfo" @getuserinfo="wxGetUserInfo">
							授权登录
						</button>
						<view class="text-white text-sm flex" style="display: none;">
							<view class="text-cut">
								新用户注册可得 <text class="">积分</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- #endif -->
		</view>
	</view>
	<view class="daui-card daui-card_mellow">
		<view class="daui-card__bd">
			<view class="daui-grid col-4 no-border">
				<navigator url="/pagesA/mine/daysign" hover-class="none" class="daui-grid__item">
					<view class="text-xxl iconfontzz icon-zd-zhengguifapiao" style="color: #9DCA06;"></view>
					<view class="text-df margin-top-xs">签到</view>
				</navigator>
				<navigator url="/pagesA/mine/wallet" hover-class="none" class="daui-grid__item">
					<view class="text-xxl iconfontzz icon-zd-qianbao" style="color: #FFB300;"></view>
					<view class="text-df margin-top-xs">钱包</view>
				</navigator>
				<navigator url="/pagesA/paycode/paycode" hover-class="none" class="daui-grid__item">
					<view class="text-xxl iconfontzz icon-zd-huodaofukuan" style="color: #53bcf5;"></view>
					<view class="text-df margin-top-xs">付款码</view>
				</navigator>
				<navigator url="/pagesA/mine/myCoupon" hover-class="none" class="daui-grid__item">
					<view class="text-xxl iconfontzz icon-redpacket" style="color: #F37D7D;"></view>
					<view class="text-df margin-top-xs">优惠券</view>
				</navigator>
				<navigator url="/pagesA/mine/myProdCollect" hover-class="none" class="daui-grid__item">
					<view class="text-xxl iconfontzz icon-zd-xihuan" style="color: #53bcf5;"></view>
					<view class="text-df margin-top-xs">收藏夹</view>
					<view class="text-xs text-gray" v-if="moonInfo.collect_num">{{moonInfo.collect_num}}条</view>
				</navigator>
				<navigator url="/pagesA/mine/myEvaluation" hover-class="none" class="daui-grid__item">
					<view class="text-xxl iconfontzz icon-evaluate" style="color: #F37D7D;"></view>
					<view class="text-df margin-top-xs">我的评价</view>
					<view class="text-xs" v-if="moonInfo.evaluation_num">{{moonInfo.evaluation_num}}</view>
				</navigator>
				<navigator url="/pagesA/mine/myProdBrowse" hover-class="none" class="daui-grid__item">
					<view class="text-xxl iconfontzz icon-footprint" style="color: #FFB300;"></view>
					<view class="text-df margin-top-xs">足迹</view>
					<view class="text-xs" v-if="moonInfo.browse_num">{{moonInfo.browse_num}}</view>
				</navigator>
				<navigator url="/pagesA/user/company" hover-class="none" class="daui-grid__item">
					<view class="text-xxl iconfontzz icon-company" style="color: #FFB300;"></view>
					<view class="text-df margin-top-xs">企业信息</view>
					<view class="text-xs" v-if="moonInfo.status_show">{{moonInfo.status_show}}</view>
				</navigator>
			</view>
		</view>
	</view>
	<view class="daui-card daui-card_mellow">
		<view class="daui-card__hdtitle" @tap="openMyOrder('0')">
			<view class="daui-cell daui-cell_access">
				<view class="daui-cell__hd">
					我的订单
				</view>
				<view class="daui-cell__bd"></view>
				<view class="daui-cell__ft">
					查看全部
				</view>
			</view>
		</view>
		<view class="daui-card__bd">
			<view class="daui-grid col-5 no-border">
				<view class="daui-grid__item" @tap="openMyOrder('1')">
					<view class="daui-grid_icon">
						<view class="iconfontzz icon-pay text-gray">
							<view class="daui-badge badge" v-if="orderStatic.wpaymentNum > 0">{{orderStatic.wpaymentNum}}</view>
						</view>
					</view>
					<view class="daui-grid_text">待付款</view>
				</view>
				<view class="daui-grid__item" @tap="openMyOrder('2')">
					<view class="daui-grid_icon">
						<view class="iconfontzz icon-deliver text-gray">
							<view class="daui-badge badge" v-if="orderStatic.wdeliveryNum > 0">{{orderStatic.wdeliveryNum}}</view>
						</view>
					</view>
					<view class="daui-grid_text">待发货</view>
				</view>
				<view class="daui-grid__item" @tap="openMyOrder('3')">
					<view class="daui-grid_icon">
						<view class="iconfontzz icon-send text-gray">
							<view class="daui-badge badge" v-if="orderStatic.wreceivedNum > 0">{{orderStatic.wreceivedNum}}</view>
						</view>
					</view>
					<view class="daui-grid_text">待收货</view>
				</view>
				<view class="daui-grid__item" @tap="openMyOrder('4')">
					<view class="daui-grid_icon">
						<view class="iconfontzz icon-evaluate text-gray">
							<view class="daui-badge badge" v-if="orderStatic.wevaluationNum > 0">{{orderStatic.wevaluationNum}}</view>
						</view>
					</view>
					<view class="daui-grid_text">待评价</view>
				</view>
				<view class="daui-grid__item" @tap="openMyOrder('5')">
					<view class="daui-grid_icon">
						<view class="iconfontzz icon-refund text-gray">
							<view class="daui-badge badge" v-if="orderStatic.refundNum > 0">{{orderStatic.refundNum}}</view>
						</view>
					</view>
					<view class="daui-grid_text">退款/售后</view>
				</view>
			</view>
		</view>
	</view>
	
	<view class="daui-card daui-card_access daui-card_mellow">
		<view class="daui-card__hd">
			我的服务
		</view>
		<view class="daui-card__bd">
			<view class="daui-grid col-5 no-border">
				<navigator url="/pagesA/mine/myConsignee" hover-class="none" class="daui-grid__item">
					<view class="daui-grid_icon">
						<view class="iconfontzz icon-address" style="color: #9DCA06;"></view>
					</view>
					<view class="daui-grid_text">收货地址</view>
				</navigator>
				<navigator url="/pagesA/evaluation/evaluation" class="daui-grid__item" style="display: none;">
					<view class="iconfontzz icon-reping" style="color: #FFB300;"></view>
					<text>店铺热评</text>
				</navigator>
				<navigator url="/pagesA/mine/invita" class="daui-grid__item" style="display: none;">
					<view class="iconfontzz icon-yaoqing" style="color: #53bcf5;"></view>
					<text>邀请有奖</text>
				</navigator>
				<navigator url="/pagesA/mine/mySubordinate" class="daui-grid__item" style="display: none;">
					<view class="iconfontzz icon-peoplelist" style="color: #F37D7D;"></view>
					<text>我的客户</text>
				</navigator>
				<navigator url="/pages/fans/fans" hover-class="none" class="daui-grid__item" style="display:none">
					<view class='icon-group_fill text-pink'></view>
					<text>我的粉丝</text>
				</navigator>
				<navigator url="/pages/coupon/coupon" hover-class="none" class="daui-grid__item" style="display:none">
					<view class='icon-ticket text-red'></view>
					<text>优惠券</text>
				</navigator>
				<view class="daui-grid__item" @click="testAlert" style="display:none">
					<view class='icon iconfontzz icon-dingdan text-blue'></view>
					<text>测试弹框</text>
				</view>
			</view>
		</view>
	</view>
	
	<block v-for="(item,index) in findList" :key="index">
		<view class="daui-card daui-card_access daui-card_mellow">
			<view class="daui-card__hd">
				{{item.name}}
			</view>
		</view>
		<view class="daui-list daui-list_three grid col-4 no-border">
			<block v-for="(item2,index2) in item.items" :key="index2">
				<view hover-class="none" class="daui-item" @tap="openPageLink(item2.page_flag, item2.page_data, item2.page_extra, item2.name)">
					<view>
						<image :src="item2.picurl" mode="aspectFit" class="daui-item-img"></image>
					</view>
					<text>{{item2.name}}</text>
				</view>
			</block>
		</view>
	</block>
	
	<view class="daui-card daui-card_access daui-card_mellow" v-if="moonInfo.shid">
		<view class="daui-card__hd">
			商家中心
		</view>
		<view class="daui-card__bd">
			<view class="daui-media daui-media_appmsg daui-media_product daui-media_margin" @tap="openShopDetail" v-if="moonInfo.shid">
				<view class="daui-media__hd" v-if="shopInfo.logo">
					<image :src="shopInfo.logo" class="daui-media__thumb"></image>
				</view>
				<view class="daui-media__bd">
					<view class="daui-media__title">{{shopInfo.name}}</view>
					<view class="daui-media__second"><text class="iconfontzz icon-people margin-right-xs"></text>{{shopInfo.contact}}</text></view>
					<view class="daui-media__second" @click="shopCall"><text class="iconfontzz icon-phone margin-right-xs"></text>{{shopInfo.phone}}</view>
					<view class="daui-media__second"><text class="iconfontzz icon-location margin-right-xs"></text>{{shopInfo.address}}</view>
					<view class="text-red margin-top-xs" v-if="shopInfo.notice"><text class="iconfontzz icon-notice margin-right-xs"></text>{{shopInfo.notice}}</view>
				</view>
				<view class="daui-media__ft">
					<text class="iconfontzz text-cyan text-xxl" @click="phoneCall(shopInfo.phone)">&#xe655;</text>
				</view>
			</view>
			<view class="daui-grid col-3 no-border" v-if="moonInfo.shid">
				<view class="daui-grid__item">
					<view class="text-xl">{{shopInfo.salevol}}</view>
					<text>销售金额</text>
				</view>
				<view class="daui-grid__item" @tap="openShopOrder(1)">
					<view class="text-xl">{{shopInfo.sendNum}}</view>
					<text>待处理订单</text>
				</view>
				<view class="daui-grid__item" @tap="openShopOrder(2)">
					<view class="text-xl">{{shopInfo.orderNum}}</view>
					<text>订单数量</text>
				</view>
			</view>
			<view class="daui-grid col-3 no-border" v-if="moonInfo.shid">
				<navigator url="/pagesB/manage/index" class="daui-grid__item" style="display: none;">
					<view class="iconfontzz icon-shopfill"></view>
					<text>商家管理</text>
				</navigator>
				<navigator url="/pagesB/manage/shop" class="daui-grid__item" style="display: none;">
					<view class="iconfontzz icon-shop"></view>
					<text>店铺管理</text>
				</navigator>
				<view class="daui-grid__item" @click="openShopOrder()">
					<view class="iconfontzz icon-dingdan1"></view>
					<text>订单管理</text>
				</view>
				<!-- #ifndef H5 -->
				<view class="daui-grid__item" @tap="doScan">
					<view class="iconfontzz icon-saomiao"></view>
					<text>扫码核销</text>
				</view>
				<!-- #endif -->
			</view>
		</view>
	</view>
	
	<view class="daui-tabbar-height margin-top"></view>
	
	<uni-popup ref="bulletinPopup">
		<view class="daui-dialog daui-dialog_sm">
			<view class="daui-dialog__hd">
				{{bulletinInfo.title}}
			</view>
			<view class="daui-dialog__bd">
				{{bulletinInfo.content}}
			</view>
			<view class="daui-flex align-center">
				<view class="daui-flex__item padding-xs">
					<button class="daui-btn bg-grey block" @click="hideBulletinPopup">我知道了</button>
				</view>
				<view class="daui-flex__item padding-xs">
					<button class="daui-btn bg-red block" @click="openPageLink(bulletinInfo.page_flag, bulletinInfo.page_data)">查看详情</button>
				</view>
			</view>
			<view class="daui-dialog-close">
				<text class="iconfontzz icon-cha" @click="hideBulletinPopup"></text>
			</view>
		</view>
	</uni-popup>
	
	<!--toast提示-->
	<daui-toast ref="toast"></daui-toast>
</view>
</template>

<script>
import danceuiTool from '../../utils/danceuiTool';
import http from "../../server/api-mine.js";
import uniPopup from "../../components/uni-popup/uni-popup.vue"
import { mapState,mapMutations } from 'vuex';
export default {
	components:{
		uniPopup
	},
	data() {
		return {
			StatusBar: this.StatusBar,
			CustomBar: this.CustomBar,
			danceData: this.danceData, //配置数据
			configInfo: {}, //配置数据
			scrollTop: 0,
			cid: '',
			platform: '',
			configInfo: [],
			orderStatic: {},
			isLogin: false,
			code: '',
			codeurl: '',
			bulletinInfo: {},
			moonInfo: {},
			shopInfo: {},
			modalName: null,
			order:[],
			findList: []
		}
	},
	onLoad(options) {
		console.log('onLoad的参数:', options);
		let obj = {};
		//#ifdef MP-WEIXIN
		obj = wx.getMenuButtonBoundingClientRect();
		//#endif
		//#ifdef MP-BAIDU
		obj = swan.getMenuButtonBoundingClientRect();
		//#endif
		//#ifdef MP-ALIPAY
		my.hideAddToDesktopMenu();
		//#endif
		
		setTimeout(() => {
			uni.getSystemInfo({
				success: res => {
					this.width = obj.left || res.windowWidth;
					this.height = obj.top ? obj.top + obj.height + 8 : res.statusBarHeight + 44;
					this.top = obj.top ? obj.top + (obj.height - 32) / 2 : res.statusBarHeight + 6;
					this.scrollH = res.windowWidth;
				}
			});
		}, 0);
		
		//#ifdef MP-WEIXIN
		//danceuiTool.loginUtil(); //登陆并保存openid
		//#endif
	},
	onShow(options){
		console.log('=====个人中心页面，onShow');
		this.getData();
	},
	onPullDownRefresh(){
		console.log('=====上拉刷新refresh');
		this.getData();
		setTimeout(() => {
			uni.stopPullDownRefresh()
		}, 200);
	},
	onPageScroll(e) {
		this.scrollTop = e.scrollTop;
	},
	methods: {
		async getData(){ //请求并获取数据
			//获取用户登陆信息
			let headers = {"Authorization":"Bearer "+this.token};
			var param = {
				cid: this.cid
			}
			let ret = await http.mine(this.$refs.toast, param, headers);
			console.log('mine页面，获取到的数据：', ret);
			var retData = ret.data;
			this.configInfo = retData.configInfo;
			this.orderStatic = retData.orderStatic;
			uni.setStorage({
				key: 'balance_name',
				data: retData.configInfo.balance_name
			})
			if(retData.moonInfo.uid > 0){
				this.isLogin = true;
				this.moonInfo = retData.moonInfo;
				if(retData.moonInfo.shid > 0) {
					this.shopInfo = retData.shopInfo;
				}
				if(retData.moonInfo.mobile_no_tip == 1) {
					uni.showModal({
						title: '提示',
						content: '您尚未绑定手机号，请先绑定手机号后再进行操作',
						success: function (res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pagesA/mine/mobile'
								});
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
				//#ifdef APP-PLUS
				this.cid = plus.push.getClientInfo().clientid;
				console.log('app推送的cid:', this.cid);
				//#endif
			}else{
				this.isLogin = false;
				this.moonInfo = retData.moonInfo;
			}
			this.findList = retData.findList;
			let storage_bulletinPopup = uni.getStorageSync('storage_bulletinPopup');
			console.log('弹出公告牌缓存:', storage_bulletinPopup);
			if(storage_bulletinPopup == 0){
				this.bulletinInfo = retData.bulletinInfo;
				if(retData.bulletinInfo.id > 0){
					this.$refs.bulletinPopup.open();
				}
			}
			//danceuiTool.showToast(this.$refs.toast, '成功');
			//danceuiTool.showToast(this.$refs.toast, '失败', 'fail');
			//danceuiTool.showToast(this.$refs.toast, '信息', 'info');
			//uni.showToast({title: '成功', duration: 2000});
			//uni.showToast({title: '失败', icon: 'error', duration: 2000});
			//uni.showToast({title: '无图标', icon: 'none', duration: 2000});
		},
		//#ifdef MP-WEIXIN
		//1.wx获取登录用户code
		wxGetUserInfo() { //微信授权获取用户信息(按钮触发)
			console.log('=====wxGetUserInfo');
			let that = this;
			if(uni.getUserProfile){
				console.log('=====getUserProfile可以调用');
				uni.getUserProfile({
					desc: '用于完善会员资料',
					success: function(infoRes) {
						var userInfo = infoRes.userInfo;
						console.log('授权获取到的用户信息userInfo:', userInfo);
						if(1){
							//uni.setStorageSync('isCanUse', false);//记录是否第一次授权 false:表示不是第一次授权
							that.saveUserData(userInfo);
						}
					},
					fail(res) {
						console.log('fail,res:', JSON.stringify(res));
					}
				});
			}
		},
		async saveUserData(userInfo) {
			//const uid = uni.getStorageSync('storage_loginuid');
			//const openid = uni.getStorageSync('storage_openid');
			//获取用户登陆信息
			const token = uni.getStorageSync('token');
			let headers = {"Authorization":"Bearer "+token};
			var param = {
				username: userInfo.nickName,
				avatar: userInfo.avatarUrl,
				gender: userInfo.gender,
				city: userInfo.city,
				province: userInfo.province,
				country: userInfo.country
			};
			let ret = await http.saveUserData(this.$refs.toast, param, headers);
			var retData = ret.data;
			console.log('saveUserData,获取到的数据：', retData);
			if(typeof retData != "undefined"){
				this.isLogin = true;
				this.moonInfo = param;
				this.moonInfo.realbalance = retData.realbalance;
				this.moonInfo.realgroup = retData.realgroup;
				this.moonInfo.store_name = retData.store_name;
				this.moonInfo.collect_num = retData.collect_num;
				this.moonInfo.follow_num = retData.follow_num;
				this.moonInfo.evaluation_num = retData.evaluation_num;
				this.moonInfo.browse_num = retData.browse_num;
				//this.qsLogin(retData.token);
			}
		},
		//#endif
		hideBulletinPopup(){
			this.$refs.bulletinPopup.close();
			uni.setStorage({
				key: 'storage_bulletinPopup',
				data: 1
			})
		},
		openLogin() {
			console.log('=====openLogin');
			//#ifdef MP-WEIXIN
			uni.navigateTo({
				url: '/pages/user/wxlogin'
			});
			//#endif
			//#ifdef APP-PLUS
			uni.navigateTo({
				url: '/pages/user/wxlogin'
			});
			//#endif
			//#ifdef H5
			uni.navigateTo({
				url: '/pages/user/login'
			});
			//#endif
		},
		openMyOrder(sort){
			console.log('openMyOrder,sort:', sort);
			//uni.setStorageSync('order_sort', sort);
			uni.navigateTo({
				url: '/pages/order/myOrder?sort='+sort
			});
		},
		openProfile() {
			uni.navigateTo({
				url: '/pagesA/mine/profile'
			});
		},
		openShopOrder(sort){
			uni.navigateTo({
				url: '/pagesB/manage/order?sort='+sort
			});
		},
		showModal(e) {
			this.modalName = e.currentTarget.dataset.target
		},
		hideModal(e) {
			this.modalName = null
		},
		doScan(){
			// 允许从相机和相册扫码
			uni.scanCode({
				success: function (res) {
					//danceuiTool.showToast(JSON.stringify(res));
					console.log('条码类型：' + res.scanType + ';条码内容：' + res.result);
					uni.navigateTo({
						url: res.result
					});
				}
			});
		},
		openPageLink(page_flag, page_data, page_extra, page_title){
			danceuiTool.dealLink(page_flag, page_data, page_extra, page_title);
		},
		openShopDetail(){
			return;
			uni.navigateTo({
				url: '/pages/shop/shopDetail?shid='+this.shopInfo.id
			})
		},
		phoneCall(phone){
			uni.makePhoneCall({
				phoneNumber: phone
			})
		},
		//#ifdef H5
		weixinBindH5(){
			let curRoute  = this.$mp.page.route; //直接获取当前页面路由
			let origin = this.danceData.webURL+'/h5/#/'+curRoute //网页授权的回调域名，这里设置的是本地端口
			let urlNow = encodeURIComponent(origin); //处理域名
			let scope = "snsapi_userinfo"; //弹框显示授权
			let appid = this.danceData.wechatAppid;
			let code = this.getUrlCode('code');
			//danceuiTool.showToast('weixinBindH5,code:'+code);
			// 截取code
			if(code == null || code === ''){ //未授权去授权
				let url =
				`https://open.weixin.qq.com/connect/oauth2/authorize?
				appid=${appid}&redirect_uri=${urlNow}&
				response_type=code&scope=${scope}&
				state=123#wechat_redirect`;
				//console.log('url:', url);
				window.location.href = url;
			}else{
				this.getOpenidAndUserinfo(code);
			}
		},
		getUrlCode(name) {
			return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
		},
		async getOpenidAndUserinfo(code) { // 拿code换取accessToken和openid最后获取用户信息
			if (code) {
				//danceuiTool.showToast('getOpenidAndUserinfo,code:'+code);
				//获取用户登陆信息
				const token = uni.getStorageSync('token');
				let headers = {"Authorization":"Bearer "+token};
				let param = {
					code: code
				}
				let ret = await http.weixinBindH5(this.$refs.toast, param, headers);
				var retData = ret.data;
				console.log('weixinBindH5操作,retData:', JSON.stringify(retData));
				this.getData();
			}
		},
		//#endif
		//#ifdef MP-WEIXIN
		weixinBindMp() {
			console.log('=====weixinBindMp开始');
			var that = this;
			//1.wx获取登录用户code
			uni.login({
				provider: 'weixin',
				success: function(loginRes) {
					let code = loginRes.code;
					console.log('用户登录的code:', code);
					that.weixinBindMpTwo(code);
				},
			});
		},
		async weixinBindMpTwo(code) {
			//获取用户登陆信息
			const token = uni.getStorageSync('token');
			let headers = {"Authorization":"Bearer "+token};
			let param = {
				code: code,
			}
			let ret = await http.weixinBindMp(this.$refs.toast, param, headers);
			var retData = ret.data;
			console.log('weixinBindMp操作，返回的数据：', JSON.stringify(retData));
			this.getData();
		},
		//#endif
		//#ifdef APP-PLUS
		weixinBindAppPlus(){
			console.log('=====weixinBindAppPlus开始');
			var that = this;
			uni.login({
				provider: 'weixin',
				success: function (loginRes) {
					console.log('loginRes.authResult:', loginRes.authResult);
					//danceuiTool.showToast('loginRes.authResult:'+loginRes.authResult);
					// 获取用户信息
					uni.getUserInfo({
						provider: 'weixin',
						success: function (infoRes) {
							//danceuiTool.showToast('用户昵称为：' + infoRes.userInfo.nickName);
							//danceuiTool.showToast(JSON.stringify(infoRes.userInfo));
							console.log('获取到的用户信息:', JSON.stringify(infoRes.userInfo));
							that.weixinBindAppPlusTwo(infoRes.userInfo);
						}
					});
				}
			});
		},
		async weixinBindAppPlusTwo(userInfo) {
			if (userInfo) {
				//获取用户登陆信息
				const token = uni.getStorageSync('token');
				let headers = {"Authorization":"Bearer "+token};
				let param = {
					openid: userInfo.openId,
					unionid: userInfo.unionId,
				}
				let ret = await http.weixinBindAppPlus(this.$refs.toast, param, headers);
				var retData = ret.data;
				console.log('weixinBindAppPlus操作,retData:', JSON.stringify(retData));
				this.getData();
			}
		},
		//#endif
	},
	computed:{
		...mapState(["memberType","token"])
	}
}
</script>


<style>
</style>